const IS_PROD = process.env.NODE_ENV === 'production';
const cdn = {
  externals: {
    vue: 'Vue',
    'element-plus': 'ElementPlus',
    AMap: 'AMap'
  },
  css: ['https://cdn.jsdelivr.net/npm/remixicon@2.5.0/fonts/remixicon.css'],
  js: ['https://unpkg.com/vue@next', 'https://unpkg.com/element-plus/lib/index.full.js']
};

module.exports = {
  publicPath: IS_PROD ? '././' : '/', // 打包相对路径
  outputDir: 'dist',
  productionSourceMap: false,
  lintOnSave: true, // 是否在保存的时候检查
  runtimeCompiler: true,
  devServer: { //环境配置
    open:true,
    port:10086,
    disableHostCheck: true,
    proxy: {
      '/@appapi': {
        target: 'http://hotfix.mxy.chinamobo.com/',//设置你调用的接口域名和端口号 别忘了加http
        changeOrigin: true,
        pathRewrite: {
            '^/@appapi': '/yii2/backend/index.php'//这里理解成用‘/appapi’代替target里面的地址，appapi 比如我要调用'http://40.00.100.100:3002/user/add'，直接写‘/api/user/add’即可
        }
    },
    }
  },
  chainWebpack: config => {
    // ============注入cdn start============
    config.plugin('html').tap(args => {
      // 生产环境或本地需要cdn时，才注入cdn
      if (IS_PROD) args[0].cdn = cdn;
      return args;
    });
    // ============注入cdn start============
  },
  configureWebpack: config => {
    // 生产环境相关配置
    if (IS_PROD) {
      // cdn
      config.externals = cdn.externals;
    }
  },
  

};
